]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
brightnessManager: Handle backlights with limited number of steps
authorSebastian Wick <sebastian.wick@redhat.com>
Wed, 6 Aug 2025 08:54:04 +0000 (10:54 +0200)
committerMarge Bot <marge-bot@gnome.org>
Thu, 7 Aug 2025 21:57:54 +0000 (21:57 +0000)
Adjusts how many steps a BrightnessScale has to ensure that every
stepUp/stepDown results in a visible change.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3826>

js/misc/brightnessManager.js

index a0402b9b4385ec53f06d7ec32350e135322eb1d7..23cd147d730eea0339ca67a69569f945745e24e9 100644 (file)
@@ -161,7 +161,12 @@ export const BrightnessManager = GObject.registerClass({
         if (monitors.length === 0) {
             this._globalScale = null;
         } else if (!this._globalScale) {
-            this._globalScale = new BrightnessScale(_('Brightness'), 1.0);
+            // Handle scales with just a few steps
+            const maxSteps = Math.max(...[...this._monitorScales.values()]
+                .map(s => s.nSteps));
+            const nSteps = Math.min(maxSteps, SCALE_VALUE_N_STEPS);
+
+            this._globalScale = new BrightnessScale(_('Brightness'), 1.0, nSteps);
             this._globalScale.connect('notify::value', () => {
                 if (this._inhibitUpdates)
                     return;
@@ -341,7 +346,16 @@ const MonitorBrightnessScale = GObject.registerClass({
     constructor(monitor, value = 1.0) {
         const name = monitor.get_monitors()[0].get_display_name();
 
-        super(name, value);
+        // Handle backlights with just a few steps
+        const maxSteps = Math.max(...monitor.get_monitors()
+            .filter(m => m.get_backlight() && m.is_active())
+            .map(m => {
+                const b = m.get_backlight();
+                return b.brightnessMax - b.brightnessMin;
+            }));
+        const nSteps = Math.min(maxSteps, SCALE_VALUE_N_STEPS);
+
+        super(name, value, nSteps);
 
         this._monitor = monitor;
         this._currentBacklightBrightness = -1;